package com.atguigu.controller;

import com.atguigu.client.UserFeignClient;
import com.atguigu.entity.OrderInfo;
import com.atguigu.entity.UserInfo;
import com.atguigu.login.TingShuLogin;
import com.atguigu.mapper.OrderInfoMapper;
import com.atguigu.query.OrderInfoQuery;
import com.atguigu.query.TrackInfoQuery;
import com.atguigu.result.RetVal;
import com.atguigu.service.OrderInfoService;
import com.atguigu.vo.AlbumListVo;
import com.atguigu.vo.OrderInfoVo;
import com.atguigu.vo.TradeVo;
import com.atguigu.vo.UserInfoVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 专辑属性值关联表 服务实现类
 * </p>
 *
 * @author Joe
 * @since 2024-11-15
 */
@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
public class OrderController {
    @Autowired
    private OrderInfoService orderInfoService;
    @Operation(summary = "确认订单")
    @PostMapping("confirmOrder")
    //@TingShuLogin  TODO id问题
    public RetVal confirmOrder(@RequestBody TradeVo tradeVo)  {
        OrderInfoVo orderInfoVo = orderInfoService.confirmOrder(tradeVo);
        return RetVal.ok(orderInfoVo);
    }

    @Operation(summary = "提交订单")
    @PostMapping("submitOrder")
    //@TingShuLogin  TODO id问题
    public RetVal submitOrder(@RequestBody OrderInfoVo orderInfoVo)  {
        HashMap<String, Object> retMap = orderInfoService.submitOrder(orderInfoVo);
        return RetVal.ok(retMap);
    }

    @Operation(summary = "校验测试")
    @PostMapping("mySubmitOrder")
    //@TingShuLogin  TODO id问题
    public void mySubmitOrder(@RequestBody @Valid OrderInfo orderInfo)  {
        System.out.println(orderInfo);
    }
    @Operation(summary = "根据订单号获取订单信息")
    @GetMapping("getOrderInfo/{orderNo}")
    public RetVal<OrderInfo> getOrderInfo(@PathVariable String orderNo) {
        OrderInfo orderAndDetail = orderInfoService.getOrderAndDetail(orderNo);
        return RetVal.ok(orderAndDetail);
    }

    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Operation(summary = "获取用户订单信息")
    @GetMapping("getUserOrderByPage/{page}/{limit}")
    public RetVal getUserOrderByPage(@PathVariable Long page, @PathVariable Long limit,String orderStatus) {
        //Long userId = AuthContextHolder.getUserId();
        Long userId = 15l;

        Page<OrderInfo> pageParam = new Page<>(page, limit);
        IPage<OrderInfo> orderInfoIPage = orderInfoService.getUserOrderByPage(userId, pageParam,orderStatus);
        return RetVal.ok(orderInfoIPage);
    }
}
